home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 22 / Amiga Format AFCD22 (Jan 1998, Issue 106).iso / -seriously_amiga- / shareware / workbench / -dopus- / empdopus / source / unassign.rexx < prev    next >
OS/2 REXX Batch file  |  1997-11-05  |  11KB  |  347 lines

  1. /*$VER: UnAssign.rexx 1.2 (18.10.97) B00ze
  2.  * For questions or comments email Booze@Videotron.CA
  3.  * Original idea (v1.0) by Charles Patterson <midian@azstarnet.com>
  4.  *
  5.  * Removes assigns pointing to the selected drawer(s) or the lister's path
  6.  * when no directory is selected.  When called from anywhere but a lister
  7.  * toolbar, it will only work on the first SOURCE lister it finds;
  8.  * called from a lister toolbar works on that lister.
  9.  *
  10.  * Try this before brute-force Unlocking some directory...
  11.  *
  12.  * USAGE: AREXX: UnAssing.rexx {Qp} {Ql}
  13.  *
  14.  * PROGRAM HISTORY
  15.  *
  16.  *  v1.1 -Knows about DEFER/PATH assigns; now, on request, only removes
  17.  *      entries to the directory so that multipath volumes will still
  18.  *      be there when you unassign parts of them; and no need to setup
  19.  *      a list of volume names anymore!
  20.  *
  21.  *  v1.2 -Improved signal traps.
  22.  *     -Made a bunch of code into functions.
  23.  *     -Requesters will be centered on the lister window whenever possible.
  24.  *     -No longer deletes the tmp files on error, it was way too dangerous.
  25.  *     -Indicates what it's using (Selected/Current Dir) in ListerTitle.
  26.  *     -Simpler code to remove leading and trailing defer indicators <[()]>
  27.  *      Unfortunately, you wont see any speed increase because of the new
  28.  *      code to handle spaces and that damn Ram Disk :(
  29.  *     -NOTE that you can't REMOVE a directory from a defered-type assign,
  30.  *      the system just doesn't handle it - Assign.rexx will now show you
  31.  *      if the assigns it finds are defered.
  32.  *     -Now handles LOGICAL/ASSIGN names with spaces WITHIN, but NOT VOLUME
  33.  *      names that contain spaces -with the exception of the Ram Disk- or
  34.  *      assign names that begin/end with spaces! You should know better
  35.  *      anyway.  It does handle spaces in directory names though (this was
  36.  *      always the case).  I'd like to have it handle any volume name, but
  37.  *      there's just no way to do it with the output Assign gives, I can't
  38.  *      figure out when the assign name ends and when the volume name
  39.  *      starts if they all have spaces in them...
  40.  */
  41.  
  42. PN='UnAssign.rexx'
  43. SH=0;WIN=0;LF='0A'x /* These are globals needed by almost every function I use! */
  44.  
  45. Options results
  46. Signal ON SYNTAX
  47. Signal ON BREAK_C
  48. Signal ON FAILURE
  49. Signal ON IOERR
  50.  
  51. Parse ARG P SH .
  52. Address VALUE P
  53.  
  54. Options failat 21
  55.  
  56. /* MAIN */
  57.  
  58.  If ~GSL() Then Call ReqERR('No Source Lister To Work With!') /* First, let's see if we got a lister to work with */
  59.  
  60.  LP=GLP(SH) /* Get terminated lister path */
  61.  
  62.  Call Pragma('D',LP) /* Get our directory name back using the volume name, non-terminated */
  63.  LP=Pragma('D')
  64.  
  65. /* Get the array of selected directories & rebuild it with the lister path */
  66.  
  67.  DL.=0
  68. 'Lister Query' SH 'Seldirs Stem DL.'
  69.  
  70.  If DL.count=0 Then Do /* Work on current directory instead of selected ones */
  71.     NL.0=LP
  72.     FL.=0
  73.    'Lister Query' SH 'Selentries Stem FL.'
  74.     If FL.count>0 Then Do x=0 To FL.count-1 /* Unselect files to indicate we work on the current dir */
  75.       'Lister Select' SH '"'FL.x'" 0'
  76.     End
  77.    'Lister Set' SH 'Title Looking for current dir...'
  78.  End
  79.  Else Do
  80.     If Right(LP,1)~=':'&Right(LP,1)~='/' Then LP=LP'/'
  81.     DL.count=DL.count-1
  82.     Do x=0 to DL.count
  83.        NL.x=LP||DL.x
  84.     End
  85.    'Lister Set' SH 'Title Looking for selected dirs...'
  86.  End
  87. 'Lister Refresh' SH 'FULL'
  88. 'Lister Set' SH 'Busy 1'
  89.  
  90. /* Get the list of assigned volumes and compare each node with our list */
  91.  
  92.  FN='T:Unassign.'Pragma('ID')'.tmp' /* output file for assign list */
  93.  
  94.  Address COMMAND 'C:Assign DIRS >'FN
  95.  If ~Open('F',FN,'R') Then Call ReqERR('Unable To Open C:Assign Outputfile!')
  96.  
  97.  Do While ~EOF('F')
  98.     ALine=Strip(ReadLN('F'))
  99.     If ALine="Directories:" Then Leave /* Read past any crap */
  100.  End
  101.  
  102.  Do While ~EOF('F')
  103.  
  104.     ALine=Strip(ReadLN('F'))
  105.     If ALine~="" Then Do
  106.  
  107.        Parse VAR ALine tmp ':' Dn
  108.  
  109.        /* Twist alot and get the volume and the assign names */
  110.  
  111.        tmp=Reverse(tmp)
  112.  
  113.        If Upper(Left(tmp,8))="KSID MAR" Then Do /* Patch for that damn "Ram Disk" */
  114.           Dn='Ram Disk:'Dn
  115.           If Verify(Right(Dn,1),'>])','M') Then Do /* Add a char to the start of Dn so that the strip routine below works */
  116.              Dn='<'Dn
  117.              tmp=Substr(tmp,10)
  118.              End
  119.           Else tmp=Substr(tmp,9)
  120.           End
  121.        Else Dn=Reverse(Trim(Left(tmp,Pos(" ",tmp))))':'Dn
  122.  
  123.        V.1=Trim(Reverse(Substr(tmp,(Pos(" ",tmp)+1))))
  124.  
  125.            /* Trace Results;Say Dn;Say V.1;Trace Off */
  126.  
  127.        If Verify(Right(Dn,1),'>])','M') Then Do /* Get rid of the Defered indicators */
  128.           Dn=Substr(Left(Dn,Length(Dn)-1),2)
  129.           Df=" DEFERED"
  130.           End
  131.        Else Df=""
  132.  
  133.            /* Trace Results;Say Dn;Trace Off */
  134.  
  135.        If V.1~="+" Then V.2=V.1 /* V2 keeps a copy of encountered volume names */
  136.        
  137.        Do x=0 to DL.count
  138.  
  139.           If NL.x=Dn Then Do
  140.  
  141.              RC=ReqEZ('Found 'Upper(V.2)': -> 'NL.x||LF||Df||LF'Remove DIRECTORY or wipe entire ASSIGN?','Wipe _Assign|Remove _Directory|_Skip')
  142.  
  143.              If RC=2 Then Address COMMAND 'C:Assign >NIL: "'V.2':" "'NL.x'" REMOVE'
  144.                Else If RC=1 Then Address COMMAND 'C:Assign >NIL: "'V.2':"'
  145.  
  146.              If DL.count~=0 Then Do
  147.                'Lister Select' SH '"'DL.x'" 0'
  148.                'Lister Refresh' SH
  149.              End
  150.           End
  151.        End
  152.     End
  153.  End
  154.  
  155. 'Lister Set' SH 'Title'
  156. 'Lister Set' SH 'Busy 0'
  157. 'Lister Refresh' SH 'FULL'
  158.  
  159.  Call Close('F')
  160. 'Command Delete' '"'FN'"' 'QUIET'
  161.  
  162.  Exit 0
  163.  
  164.       /*-----------------------------------------------------------
  165.                              Get Source Lister
  166.                   You MUST Initialise WIN and SH to Zer0!
  167.       -----------------------------------------------------------*/
  168.  
  169. /* Returns the GLOBALS SH and WIN, the idea being that all requesters
  170.  * should appear within the calling window.  When SH is already set to
  171.  * a non-zero numeric value, we assume we've parsed a valid {Ql} arg.
  172.  *
  173.  * When SH is zero, we query Dopus for a SOURCE-Lister.  If we are
  174.  * passed 'D' we try for a DEST-Lister when no SOURCE-Lister can be
  175.  * obtained.  If we are passed 'A' we try for that when DEST fails. */
  176.  
  177. GSL: PROCEDURE EXPOSE P LF PN SH WIN /* USAGE: Success=GSL(Scantype) */
  178.  
  179.    If Datatype(SH)~="NUM" Then Call ReqERR('UnInitialized SH/SourceHandle!')
  180.  
  181.    If SH=0 Then Do
  182.  
  183.       Parse UPPER ARG STyp
  184.       If STyp~="D"|STyp~="A" Then STyp="S"
  185.  
  186.       SL.=0
  187.      'Lister Query Source Stem SL.'
  188.       If SL.count=0 Then If STyp="S" Then Return(0)
  189.          Else Do
  190.            'Lister Query Dest Stem SL.'
  191.             If SL.count=0 Then If STyp="D" Then Return(0)
  192.                Else Do
  193.                  'Lister Query ALL Stem SL.'
  194.                   If SL.count=0 Then Return(0)
  195.                End
  196.          End
  197.  
  198.       SH=SL.0
  199.    End
  200.  
  201.   'Lister Set' SH 'Source'
  202.   'Lister Query' SH 'Window'
  203.    If RESULT~=0&Datatype(RESULT)='NUM' Then WIN=RESULT
  204.    Else WIN=0
  205.    Return(1)
  206.  
  207.       /*-----------------------------------------------------------
  208.                         Get Terminated Lister Path
  209.       -----------------------------------------------------------*/
  210.  
  211. GLP: PROCEDURE EXPOSE P LF PN SH WIN /* USAGE: Path=GLP(ListerHandle) */
  212.  
  213.    Parse ARG LH
  214.   'Lister Query' LH 'PATH'
  215.    If RESULT=""|RESULT="RESULT" Then Call ReqERR('Unable To Obtain Lister PATH!')
  216.    Else Do
  217.       LP=RESULT
  218.       If Right(LP,1)~=':'&Right(LP,1)~='/' Then LP=LP'/'
  219.    End
  220.    Return(LP)
  221.  
  222.       /*-----------------------------------------------------------
  223.                                 Requesters
  224.             All functions assume the current port to be Dopus's
  225.       -----------------------------------------------------------*/
  226.  
  227. /* All requesters work on the calling lister, specified by the globals
  228.  * SH/WIN, when set.  To force a lister to appear centered on the dopus
  229.  * screen instead, supply the extra switch 'NW' for 'NoWin-Centered' */
  230.  
  231. ReqEZ: PROCEDURE EXPOSE P LF PN FN SH WIN /* USAGE: GReqEZ('requestertext','gadgets'[,'NW']) */
  232.  
  233.    Parse ARG TXT,GADGETS,A
  234.    A=Upper(A)
  235.  
  236.    If ~Show('L',"rexxreqtools.library") Then CALL AddLib('rexxreqtools.library',0,-30,0) /* Try to get rexxreqtools loaded */
  237.    If ~Show('L',"rexxreqtools.library") Then Do
  238.        GADGETS=Compress(GADGETS,'_')
  239.        If SH=0|Datatype(SH)~="NUM"|A="NW" Then RCMD='Dopus Request'
  240.        Else RCMD='Lister Request 'SH
  241.        RCMD' "'TXT'" 'GADGETS
  242.        Choice=RC
  243.    End
  244.    Else Do
  245.       If WIN=0|Datatype(WIN)~="NUM"|A="NW" Then Do
  246.         'Dopus Screen'
  247.          Parse VAR RESULT S .
  248.          RTAG='RT_PubScrName='S' rt_reqpos=reqpos_centerscr'
  249.          End
  250.       Else RTAG='RT_Window='WIN' rt_reqpos=reqpos_centerwin'
  251.       Choice=rtEZRequest(TXT,GADGETS,PN,RTAG' rtez_flags=ezreqf_centertext')
  252.    End
  253.    Return Choice
  254.  
  255. ReqERR: PROCEDURE EXPOSE P LF PN FN SH WIN /* USAGE: GReqERR('requestertext'[,'NW']) - Quits! */
  256.  
  257.    Parse ARG TXT,A
  258.    A=Upper(A)
  259.  
  260.   'Command Flash'
  261.    If ~Show('L',"rexxreqtools.library") Then CALL AddLib('rexxreqtools.library',0,-30,0) /* Try to get rexxreqtools loaded */
  262.    If ~Show('L',"rexxreqtools.library") Then Do
  263.        If SH=0|Datatype(SH)~="NUM"|A="NW" Then RCMD='Dopus Request'
  264.        Else RCMD='Lister Request 'SH
  265.        RCMD' "+++ 'PN' Error +++'LF||TXT'" OK'
  266.    End
  267.    Else Do
  268.       If WIN=0|Datatype(WIN)~="NUM"|A="NW" Then Do
  269.         'Dopus Screen'
  270.          Parse VAR RESULT S .
  271.          RTAG='RT_PubScrName='S' rt_reqpos=reqpos_centerscr'
  272.          End
  273.       Else RTAG='RT_Window='WIN' rt_reqpos=reqpos_centerwin'
  274.       CALL rtEZRequest('+++ 'PN' Error +++'LF||TXT,,PN,RTAG' rtez_flags=ezreqf_centertext rt_idcmpflags=idcmp_vanillakey')
  275.    End
  276.    If SH~=0 Then Do
  277.      'Lister Set' SH 'Busy 0'
  278.      'Lister Set' SH 'Title'
  279.      'Lister Refresh' SH 'FULL'
  280.    End
  281.    Exit 20
  282.  
  283.       /*-----------------------------------------------------------
  284.                                ERROR HANDLERS
  285.       -----------------------------------------------------------*/
  286.  
  287. BREAK_C:
  288.  
  289.    Address VALUE P
  290.    If SH~=0 Then Do
  291.      'Lister Set' SH 'Busy 0'
  292.      'Lister Set' SH 'Title'
  293.      'Lister Refresh' SH 'FULL'
  294.       RCMD='Lister Request 'SH
  295.       End
  296.    Else RCMD='Dopus Request'
  297.   'Command Flash'
  298.    RCMD' "+++ Break! +++" OK'
  299.    Call Close('F')
  300.    Exit 0
  301.  
  302. SYNTAX:
  303.  
  304.    RCX=RC
  305.    Address VALUE P
  306.    If SH~=0 Then Do
  307.      'Lister Set' SH 'Busy 0'
  308.      'Lister Set' SH 'Title'
  309.      'Lister Refresh' SH 'FULL'
  310.       RCMD='Lister Request 'SH
  311.       End
  312.    Else RCMD='Dopus Request'
  313.   'Command Flash'
  314.    RCMD' "+++ Syntax Error +++'LF'('RCX') at line 'SIGL||LF||errortext(RCX)'" OK'
  315.    Call Close('F')
  316.    Exit 20
  317.  
  318. FAILURE:
  319.  
  320.    Address VALUE P
  321.    If SH~=0 Then Do
  322.      'Lister Set' SH 'Busy 0'
  323.      'Lister Set' SH 'Title'
  324.      'Lister Refresh' SH 'FULL'
  325.       RCMD='Lister Request 'SH
  326.       End
  327.    Else RCMD='Dopus Request'
  328.   'Command Flash'
  329.    RCMD' "+++ Failure +++'LF'Something failed at line 'SIGL'" OK'
  330.    Call Close('F')
  331.    Exit 20
  332.  
  333. IOERR:
  334.  
  335.    Address VALUE P
  336.    If SH~=0 Then Do
  337.      'Lister Set' SH 'Busy 0'
  338.      'Lister Set' SH 'Title'
  339.      'Lister Refresh' SH 'FULL'
  340.       RCMD='Lister Request 'SH
  341.       End
  342.    Else RCMD='Dopus Request'
  343.   'Command Flash'
  344.    RCMD' "+++ I/O Error +++'LF'I/O Operation failed at line 'SIGL'" OK'
  345.    Call Close('F')
  346.    Exit 20
  347.